package com.example.demo.zaqizabatest.函数接口;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BinaryOperator;

/**
 * @ClassName BinaryOperatorTest BinaryOperator<T> 表示接受两个相同类型的参数，并返回一个同一类型的结果的操作
 * @Author lys4134
 * @Date 2021/08/13 14:56:46
 * @Description BinaryOperatorTest
 * @Version 1.0
 **/
public class BinaryOperatorTest {
    public static void main(String[] args) {
        eval(AHelp.list1, AHelp.list2, (a, b) ->a + b);
    }

    public static List<Integer> eval(List<Integer> list1, List<Integer> list2, BinaryOperator<Integer> binaryOperator) {
        List<Integer> result = new ArrayList<>();
        if (CollectionUtils.isEmpty(list1) || CollectionUtils.isEmpty(list2) || list1.size() != list2.size()) {
            return null;
        }
        for (int i = 0; i < list1.size(); i++){
            Integer apply = binaryOperator.apply(list1.get(i), list2.get(i));
            result.add(apply);
        }
        System.out.println(result);
        return result;
    }
}
